//
// Created by 33145 on 2023/1/17.
//
#include "../sylar/scheduler.h"
#include "../sylar/hook.h"
#include "../sylar/iomanager.h"

sylar::Logger::ptr g_logger = SYLAR_LOG_NAME("root");

void test_fiber() {
  SYLAR_LOG_INFO(g_logger) << "test in fiber";
  // sylar::set_hook_enable(true);
  // sleep(2);
}
void test() {
  SYLAR_LOG_INFO(g_logger) << "main";
  sylar::Scheduler sc(1, false);
  // printf("%p\n", &sc);
  sc.start();
  sc.schedule(&test_fiber);
  // std::cout << "hello world" << std::endl;
  sc.stop();
  SYLAR_LOG_INFO(g_logger) << "over";
}

void run_in_fiber2() {
  SYLAR_LOG_INFO(g_logger) << "run_in_fiber2 begin";
  SYLAR_LOG_INFO(g_logger) << "run_in_fiber2 end";
}

void run_in_fiber() {
  SYLAR_LOG_INFO(g_logger) << "run_in_fiber begin";
  sylar::Fiber::ptr fiber(new sylar::Fiber(run_in_fiber2, 0, true));
  fiber->swapIn();

  SYLAR_LOG_INFO(g_logger) << "run_in_fiber end";
}
int main(int argc, char** argv) {
  sylar::Scheduler s;
  s.schedule(run_in_fiber);
  s.start();
  s.stop();
  return 0;
}